package model

import (
    "git.inspur.com/x/models"
)

type ProxyServer struct {
    Id         string `xorm:"pk"`
    ServerIp   string
    RootP6d    string `xorm:"root_password"`
    ServerName string
    Mac        string
    Ram        int
    Cpu        int
    System     string
    CreateTime models.Time `xorm:"created"`
    UpdateTime models.Time `xorm:"updated"`
    DeleteTime models.Time `xorm:"deleted"`
}

func (p ProxyServer) TableName() string {
    return "fcs_proxy_server"
}

func GetServerById(id string) (*ProxyServer, error) {
    p := &ProxyServer{}
    if _, err := models.Engine.ID(id).Get(p); err != nil {
        _ = logger.Error("GetServerById: Get server err, ", err)
        return nil, err
    }
    return p, nil
}

func GetAllServer() ([]*ProxyServer, error) {
    proxyServers := make([]*ProxyServer, 0)
    if err := models.Engine.Find(&proxyServers); err != nil {
        _ = logger.Error("GetAllServer: Get server err, ", err)
        return nil, err
    }
    return proxyServers, nil
}

func CreateServer(server *ProxyServer) (*ProxyServer, error) {
    if _, err := models.Engine.Insert(server); err != nil {
        _ = logger.Error("CreateOrder: insert error: %v", err)
        return nil, err
    }
    return server, nil
}
